package api

import (
    "github.com/gogf/gf/frame/g"
    "github.com/gogf/gf/net/ghttp"
    "github.com/gogf/gf/os/gcron"
    "github.com/gogf/gf/os/gtime"
    "github.com/gogf/gf/util/gconv"
    "webserver/app/service"
)

var ScriptApi = scriptApi{}

type scriptApi struct{}

func (a *scriptApi) InitCrontab(r *ghttp.Request) {
    crontabStatus := g.Cfg().Get("crontab.status")
    if gconv.Bool(crontabStatus) {
        //每天15:10执行一次: format: 秒 分 时  日 月 周
        _, _ = gcron.AddSingleton("0 10 7 * * *", func() { // 15点-8=7，设置的时区暂未生效，先减8使用
        	g.Log().Line().Println("[CRONTAB][0 5 15 * * *]")
            if gtime.Now().Weekday().String() == "Saturday" || gtime.Now().Weekday().String() == "Sunday" {
                g.Log().Line().Println("[CRONTAB][周末]")
            } else {
                _ = service.HiFuturesQuoteService.CheckAllFuturesQuote(r)
            }
        })

        r.Response.Writeln("success")
    }

    r.Response.Writeln(gtime.Datetime())
}

